﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Wheeler.Web.ViewModels;

namespace Wheeler.Web.Utility
{
    public static class UserInfo
    {
        /// <summary>
        /// Determines whether the currently logged in user is a Admin or not
        /// </summary>
        public static bool IsAdmin
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfAdmin)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Determines whether the currently logged in user is a Job Seeker
        /// </summary>
        public static bool IsOperator
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfOperator)
                    return true;
                return false;
            }
        }

        /// <summary>
        /// Gets the currently logged in users group name
        /// </summary>
        /// <returns></returns>
        public static String GetUserType()
        {
            if (SessionCache.CurrentUser != null)
            {                
                GroupViewModel group = ApplicationCache.UserGroups.FirstOrDefault(P => P.ID == SessionCache.CurrentUser.GroupID);
                return group.Name;
            }
            return "Not Logged In";
        }

        /// <summary>
        /// Checks wheather an user can edit a vehicle information
        /// </summary>
        /// <param name="isVehicleVerified"></param>
        /// <param name="hasPublishedTest"></param>
        /// <returns></returns>
        public static bool CanEditVehicleInfo(bool hasPublishedTest)
        {   
            if (UserInfo.IsOperator)
            {
                if (!hasPublishedTest)
                    return true;
            }
            else if (UserInfo.IsAdmin)
                return true;

            return false;
        }

        /// <summary>
        /// Checks whether an user can edit a test result
        /// </summary>
        /// <param name="hasConfirmed"></param>
        /// <param name="hasPublished"></param>
        /// <returns></returns>
        public static bool CanEditTestResult(bool hasConfirmed, bool hasPublished)
        {
            if (UserInfo.IsOperator)
            {
                if (!hasConfirmed && !hasPublished)
                //if(!hasPublished)
                    return true;
            }
            else if (UserInfo.IsAdmin)
                return true;

            return false;
        }
    }

    #region User Menu Enumerations

    public enum OperatorMenu
    {
        Dashboard,
        ChangePassword,
        //RegisterVehicle,
        //EnterTestResult,
        //Search_Vehicles,
        //Search_TestResult,
        //Coverletter,
        //Resume,
        //FaboriteJobs,
        //AppliedJobs,
        //InterviewRequests,
        Vehicles,
        TestResults,
        None
    }
    public enum EmployerMenu
    {
        Dashboard,
        CompanyProfile,
        ManageJobs,
        ManageContacts,
        SearchResume,
        FavoriteResumes,
        PublishedJobs,
        ManageApplications,
        FavoriteJobSeekers,
        Subscriptions,
        Settings,
        None
    }
    public enum AdminMenu
    {
        Dashboard,
        Import,
        EditTestResult,
        EditVehicle,
        ManageUser,
        BackupDatabase,
        //ManageLookupData,
        //ManagePackage,
        //ManageContents,
        //ManageCategory,
        //SearchConfig,
        //Settings,
        None
    }

    #endregion

    //public class TestStatuses
    //{
    //    public const String PASSED = "P";
    //    public const String FAILED = "F";
    //    public const String NOT_TESTED = "N";
    //}
}